home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 February / LiquidLibrary 2005 February - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_dps2.ps < prev    next >
Text File  |  2003-01-03  |  7KB  |  207 lines

  1. %    Copyright (C) 1990, 1996, 1997, 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Initialization file for basic Display PostScript functions
  7. % that are also included in Level 2.
  8.  
  9. level2dict begin
  10.  
  11. % ------ Halftones ------ %
  12.  
  13. /.makestackdict
  14.     { { counttomark -1 roll } forall .dicttomark
  15.     } bind def
  16. /currenthalftone        % - currenthalftone <dict>
  17.     { mark .currenthalftone
  18.        { { exch pop }        % halftone
  19.          { /HalftoneType 1        % screen
  20.         { /Frequency /Angle /SpotFunction }
  21.            .makestackdict
  22.          }
  23.          { /HalftoneType 2        % colorscreen
  24.         { /RedFrequency /RedAngle /RedSpotFunction
  25.           /GreenFrequency /GreenAngle /GreenSpotFunction
  26.           /BlueFrequency /BlueAngle /BlueSpotFunction
  27.           /GrayFrequency /GrayAngle /GraySpotFunction
  28.         }
  29.            .makestackdict
  30.          }
  31.        }
  32.       exch get exec
  33.     } odef
  34. % Define sethalftone so it converts types 1-4 to type 5.
  35. /.makehalftoneRGBV {    % <dict> <type> <keys> <keysRGBV>
  36.   4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
  37.   14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
  38.         % stack: v0 v1 v2 type keys comp
  39.     mark
  40.     2 index 0 get 8 -1 roll
  41.     4 index 1 get 9 -1 roll
  42.     6 index 2 get 10 -1 roll
  43.         % stack: type keys comp mark k0 v0 k1 v1 k2 v2
  44.     /HalftoneType 10 index .dicttomark
  45.     counttomark 2 roll
  46.   } forall pop pop
  47.   /Default 1 index .dicttomark exch pop { .sethalftone5 }
  48. } bind def
  49.  
  50. % The value of each entry in .halftonetypes is a procedure:
  51. %    <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
  52. % This allows us to use these procedures both for actually implementing
  53. % sethalftone and for converting subsidiary dictionaries of HalftoneType 5
  54. % halftones.
  55. systemdict begin
  56. 15 dict /.halftonetypes 1 index def begin
  57.   1 {
  58.     mark exch /Default exch .dicttomark { .sethalftone5 }
  59.   } bind def
  60.   2 {
  61.     1 { /Frequency /Angle /SpotFunction } {
  62.       /RedFrequency /RedAngle /RedSpotFunction
  63.       /GreenFrequency /GreenAngle /GreenSpotFunction
  64.       /BlueFrequency /BlueAngle /BlueSpotFunction
  65.       /GrayFrequency /GrayAngle /GraySpotFunction
  66.     } .makehalftoneRGBV
  67.   } bind def
  68.   3 {
  69.     mark exch /Default exch .dicttomark { .sethalftone5 }
  70.   } bind def
  71.   4 {
  72.     3 { /Width /Height /Thresholds } {
  73.       /RedWidth /RedHeight /RedThresholds
  74.       /GreenWidth /GreenHeight /GreenThresholds
  75.       /BlueWidth /BlueHeight /BlueThresholds
  76.       /GrayWidth /GrayHeight /GrayThresholds
  77.     } .makehalftoneRGBV
  78.   } bind def
  79.   5 {
  80.     pop dup length dict copy
  81.     mark 1 index {
  82.         % Even HalftoneType 5 dictionaries have entries other than
  83.         % subsidiary halftone dictionaries.
  84.       dup type /dicttype ne {
  85.     0
  86.       } {
  87.     dup /HalftoneType .knownget not { 0 } if
  88.       } ifelse dup 5 gt {
  89.         % Stack: dict mark ... keyN dictN httypeN
  90.         % Assume that all HalftoneTypes > 5 convert to 5.
  91.     1 index 3 1 roll
  92.     //.halftonetypes exch get exec pop /Default get
  93.         % Stack: dict mark ... keyN setdict'N htdict'N
  94.     counttomark 1 add index 3 index 4 -1 roll put
  95.       } {
  96.     pop
  97.       } ifelse
  98.     } forall .dicttomark { .sethalftone5 }
  99.   } bind def
  100. end
  101. end
  102. /sethalftone {        % <dict> sethalftone -
  103.     % We must create the new dictionary in the same VM as the
  104.     % operand; otherwise, invalidaccess errors may occur.
  105.   .currentglobal 1 index dup gcheck .setglobal
  106.   dup //.halftonetypes 1 index /HalftoneType get get exec exec
  107.   .setglobal pop
  108. } odef
  109. % Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
  110. % and to insert the Frequency and Angle into Type 1 halftones, per
  111. % Adobe TN 5085.
  112. /.fixsethalftonescreen        % <freq> <angle> <dict> .fix...screen
  113.                 %   <freq> <angle> <dict> <dict'>
  114.  { dup dup /HalftoneType get 1 eq
  115.     { dup wcheck not { dup length .copydict } if
  116.       dup /Frequency 5 index put
  117.       dup /Angle 4 index put
  118.     }
  119.    if
  120.  } bind def
  121. /setscreen        % <ignore*2> <dict> setscreen -
  122.     { dup type /dicttype eq
  123.        { .fixsethalftonescreen sethalftone pop pop pop }
  124.        { //setscreen }
  125.       ifelse
  126.     } odef
  127. /setcolorscreen        % <ignore*11> <dict> setcolorscreen -
  128.     { dup type /dicttype eq
  129.        { .fixsethalftonescreen sethalftone 12 { pop } repeat }
  130.        { //setcolorscreen }
  131.       ifelse
  132.     } odef
  133. % Redefine currentscreen and currentcolorscreen to extract the Frequency
  134. % and Angle from Type 1 halftones, per Adobe TN 5085.
  135. /.fixcurrenthalftonescreen    % <dict> .fix... <freq> <angle> <proc>
  136.  { dup /HalftoneType get 1 eq
  137.     { dup /Frequency get 1 index /Angle get }
  138.     { 60 0 }
  139.    ifelse 3 2 roll
  140.  } bind def
  141. /currentscreen        % - currentscreen 60 0 <dict>
  142.     { .currenthalftone
  143.        { { .fixcurrenthalftonescreen }    % halftone
  144.          { }                % screen
  145.          { 12 3 roll 9 { pop } repeat    % colorscreen
  146.            dup type /dicttype eq { .fixcurrenthalftonescreen } if
  147.          }
  148.        }
  149.       exch get exec
  150.     } odef
  151. /currentcolorscreen    % - currentcolorscreen (60 0 <dict>)*4
  152.     { .currenthalftone
  153.        { { .fixcurrenthalftonescreen 3 copy 6 copy }    % halftone
  154.          { 3 copy 6 copy }            % screen
  155.          { }                % colorscreen
  156.        }
  157.       exch get exec
  158.     } odef
  159.  
  160. % ------ User objects ------ %
  161.  
  162. /.UserObjects {
  163.   .userdict /UserObjects
  164. } odef
  165. % In order to get proper error recovery behavior, we need to be careful
  166. % not to pop any operands from the stack until we're done.
  167. % The code below faithfully duplicates the apparent array-growing
  168. % behavior of Adobe interpreters.
  169. /defineuserobject {        % <index> <value> defineuserobject -
  170.   .UserObjects .knownget {
  171.     length dup 3 index le {
  172.         % Stack: index value len
  173.       2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
  174.       .localvmarray .UserObjects get
  175.       1 index copy pop
  176.       .UserObjects 3 -1 roll put
  177.     } {
  178.       pop
  179.     } ifelse
  180.   } {
  181.     .UserObjects 3 index 1 add 10 .max .localvmarray put
  182.   } ifelse
  183.   .UserObjects get 2 index 2 index put pop pop
  184. } odef
  185. /execuserobject {        % <index> execuserobject -
  186.   .UserObjects get 1 index get exch pop exec
  187. } odef
  188. /undefineuserobject {        % <index> undefineuserobject -
  189.   .UserObjects get 1 index null put pop
  190. } odef
  191.  
  192. % ------ Cache control ------ %
  193.  
  194. % Dummy definitions for cache control operators
  195.  
  196. /ucachestatus {            % - ucachestatus -mark- ? ? ? ? <size>
  197.     mark 0 0 0 0 .userdict /.ucachesize .knownget not { 0 } if
  198. } odef
  199. /setucacheparams {        % -mark- ... <size> setucacheparams -
  200.         % Provoke an appropriate error if needed.
  201.     counttomark 1 lt { () 0 get } if
  202.     0 or .userdict /.ucachesize 2 index 0 .max put cleartomark
  203. } odef
  204.  
  205. end                % level2dict
  206.